using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class _controls_MainNavigation : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            CreateMenu();
        }
    }
    private void CreateMenu()
    {

        rptMenu.DataSource = GetMenuList();
        rptMenu.DataBind();
    }

    private List<SiteMapNode> GetMenuList()
    {
        List<SiteMapNode> nodes = new List<SiteMapNode>();
        nodes.Add(SiteMap.RootNode);
        foreach (SiteMapNode node in SiteMap.RootNode.ChildNodes)
        {
            GetChildNodes(node, nodes);
        }
        return nodes;
    }

    private void GetChildNodes(SiteMapNode node, List<SiteMapNode> nodes)
    {
        if (node.HasChildNodes)
        {
            foreach (SiteMapNode n in node.ChildNodes)
            {
                GetChildNodes(n, nodes);
            }
        }
        nodes.Add(node);
    }


    protected string GetDataItem(object data)
    {
        SiteMapNode node = data as SiteMapNode;
        if (node.Url.ToLower() == Request.Url.AbsolutePath.ToLower())
        {
            return String.Format("<li id='current'><strong>{0}</strong></li>", node.Title);
        }
        return String.Format("<li><a href='{0}'>{1}</a></li>", VirtualPathUtility.ToAbsolute(node.Url), node.Title);
    }
}
